package com.example.chao.myphotosearch.adapters;

import android.net.Uri;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.chao.myphotosearch.Listener.StartSearchActivityListener;
import com.example.chao.myphotosearch.R;
import com.example.chao.myphotosearch.dao.RecommendContent;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

/**
 * Created by chao on 2016/4/25.
 */
public class CycleViewPagerAdapter extends PagerAdapter {
    private List<RecommendContent> recommendContents;
    public CycleViewPagerAdapter(List<RecommendContent> recommendContents) {
        this.recommendContents = recommendContents;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        position = position%recommendContents.size();
        SimpleDraweeView view = (SimpleDraweeView) LayoutInflater.from(container.getContext()).inflate(R.layout.cycle_view_item,container,false);
        view.setImageURI(Uri.parse(recommendContents.get(position).getImgUrl()));
        view.setOnClickListener(new StartSearchActivityListener(recommendContents.get(position)));
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
